<template>
  <div class="app">
    <h1>我是App组件</h1>
    <h3 v-show="toy">儿子很孝顺游戏机给我了：{{toy}}</h3>
    <h3 v-show="computer">儿子很孝顺电脑给我了：{{computer}}</h3>
    <!-- 下面这行代码的含义是：给Child组件实例绑定了一个send-toy事件，只要事件被触发，那么getToy就调用 -->
    <Child 
      @send-toy="getToy"
      @send-computer="getComputer"
      @click.native="handleClick"
    />

    <!-- <Child ref="haizi"/> -->
  </div>
</template>

<script>
  import Child from './components/Child'

  export default {
    name:'App',
    components:{Child},
    data() {
      return {
        toy:'',
        computer:''
      }
    },
    methods: {
      getToy(value){
        this.toy = value
      },
      getComputer(value){
        this.computer = value
      },
      handleClick(value){
        console.log('App',value)
      }
    },
    /* mounted() {
      this.$refs.haizi.$on('send-toy',this.getToy)
    }, */
  }
</script>

<style>
  .app {
    background-color: gray;
    padding: 20px;
  }
</style>